package com.uchedao.seller.ui.carlist;

import android.content.Context;
import android.os.Bundle;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.baidu.mobstat.StatService;
import com.uchedao.seller.http.VolleyUtil;
import com.uchedao.seller.ui.user.LoginFragment;
import com.uchedao.ulibrary.fragment.FragmentMrg;

/**
 * 百度统计－－Fragment
 * Created by zhengxizhen on 15/10/13.
 */
public abstract class BaseFragForBaidu extends BaseFragment implements IOnResultBack {

    /**
     * 当前软件Context
     */
    protected Context mContext;

    /**
     * 页面标签
     */
    protected String TAG = "BaseFragment";
    /**
     *
     * */
    protected RequestQueue mQueue;

    /**
     * 设置页面标签
     */
    protected abstract String getActivityTag();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = getActivityTag();
        //获取单例网络请求队列
        mQueue = VolleyUtil.getInstance().getRequestQueue();
        TAG = getActivityTag();
        // 调试百度统计SDK的Log开关，可以在Eclipse中看到sdk打印的日志，发布时去除调用，或者设置为false
        StatService.setDebugOn(false);
    }

    @Override
    public abstract int getViewLayoutId();

    @Override
    public abstract void initView();

    public String[] getStrArr(int resId) {
        return getActivity().getResources().getStringArray(resId);
    }
    /**
     * 网络请求添加到请求队列中
     */
    public void addQueue(Request queue) {
        //设置标签
        queue.setTag(TAG);
        if (mQueue != null) {
            mQueue.add(queue);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        StatService.onPageEnd(mContext, TAG);
        //取消当前页面所有的网络请求
        if (mQueue != null) {
            mQueue.cancelAll(TAG);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        StatService.onPageStart(mContext, TAG);
    }

    public void toBack(BaseFragment fragment){
        FragmentMrg.toBack(fragment);
    }

    /**
     * 进入登录界面
     * */
    public void toLogin() {
        toFragment(LoginFragment.getInstance(), true, true);
    }
}
